package com.xzc.lease.web.app.service.impl;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.xzc.lease.web.app.service.SmsService;
import jakarta.websocket.SendResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SmsServiceImpl implements SmsService {

    @Autowired
    private Client client;

    /**
     * 发送短信验证码
     */
    public void sendCode(String phone, String code) {
        SendSmsRequest request = new SendSmsRequest();
        request.setPhoneNumbers(phone)
                //设置签名名称
                .setSignName("阿里云短信测试")
                //设置模板code
                .setTemplateCode("SMS_154950909")
                //设置模板参数的值
                .setTemplateParam("{\"code\":\"" + code + "\"}");

        try {
            client.sendSms(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
